package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Menu;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface MenuDao {
    @Select("select * from t_user where username = #{user}")
    User findByusername(String username);

    @Select("select * from t_user_role ur ,t_role r where ur.user_id = #{id} and ur.role_id = r.id")
    Set<Role> findAll(Integer id);

    @Select("select * from t_menu m,t_role_menu rm where m.id = rm.menu_id and rm.role_id = #{id}")
    List<Menu> findByMenu(Integer id);

    @Select("select * from t_menu where parentMenuId = #{id}")
    List<Menu> findByMid(Integer id);

    @Select("select * from t_menu")
    List<Menu> selectAll();

    //@Select("select * from t_menu where level = 1")
    Page<Menu> selectAllByName(String queryString);

    @Select("select * from t_menu where parentMenuId = #{id}")
    List<Menu> findById(Integer id);

    @Insert("insert into t_menu values(null,#{name},#{linkUrl},#{path},#{priority},#{icon},#{description},#{parentMenuId},#{level})")
    void add(Menu menu);

    void update(Menu menu);

    @Select("select count(*) from t_role_menu where menu_id = #{id}")
    Integer findRoleById(int id);

    @Delete("DELETE from t_role_menu where menu_id = #{id}")
    void deleteRoleAndMenu(int id);

    @Delete("delete from t_menu where id = #{id}")
    void delete(int id);

    @Select("select * from t_menu where path=#{path}")
    Menu findByPath(int path);
}
